<?php 
namespace Admin\Controller;
use Think\Controller;
class ConfigController extends Controller{

	public function index(){
		//网站基本配置
		$config=M('config')->where("config_type=1")->select();

		foreach ($config as $i => $c) {
                $html = ''; 
                switch ($c['form_type']) {
                    case 1: //文本框
                        $html = "<input type='text' class='form-control' name='config[{$c['name']}]' value='{$c['value']}'/>";
                        break;
                    case 2: //单选框
                        $param = explode(',', $c['param']);
                        foreach ($param as $p) {
                            $par = explode(':', $p);
                            $checked = $c['value'] == $par[0] ? 'checked=""' : '';
                            $html .= "<label class='checkbox-inline'><input type='radio'  name='config[{$c['name']}]' $checked value='{$par[0]}'/> {$par[1]}</label>";
                        }
                        break;
                }
                $config[$i]['html'] = $html;
            }
            //网站水印
        $data=M('config')->where("config_type=2")->select();
        $water=array();
        foreach ($data as $i=>$w) {
        	$water[$w['name']]=$w;
        }
        	$this->assign('water',$water);
            $this->assign('data', $config);
            $this->display();

	}

	//编
	public function edit(){
		$Model=D('Config');
		if($Model->editConfig()){
			$this->success("编辑成功");
		}else{
			$this->error('编辑失败');
		}
	}

	public function editWater(){
		$Model=D('Config');
		if($Model->editWater()){
			$this->success("编辑成功");
		}else{
			$this->error('编辑失败');
		}
	}

	//模板风格
	public function style(){

	}
//缓存
	public function updateCache(){
		$Model=D('Config');
		if($Model->updateCache()){
			$this->success("缓存成功");
		}else{
			$this->error("缓存失败");
		}
	}

}





 ?>